<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		<meta name="Generator" content="EditPlus®">
		<meta name="Author" content="梦想星辰大海">
		<meta name="Keywords" content="">
		<meta name="Description" content="">
		<title>cms后台模板</title>
		<link rel="stylesheet" href="${BASE_PATH}/static/book/res/lib/layui/css/layui.css">
	</head>
	<body>
		<form class="layui-form" action="add.htm" role="form" method="post">
			<div class="layui-form-item">
		        <label for="number" class="layui-form-label">图书编号:</label>
				<div class="layui-input-block">
		      		<input type="text" name="number" id="number" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
	    		</div>
    		</div>
		  	<div class="layui-form-item layui-inline">
		        <label for="cate" class="layui-form-label">图书分类</label>
				<div class="layui-input-inline">
					<select name="cateId" lay-verify="required" lay-search="">
					<#list cateList as cate>
						<option value="${cate.cateId}"  >${cate.name}</option>
					</#list>
					</select>
				</div>
    		</div>
    		<div class="layui-form-item">
		        <label for="urlPic" class="layui-form-label">图片:</label>
				<div class="layui-input-inline">
					<input type="file" name="urlPic" id="urlPic" class="layui-upload-file" lay-title="添加图片"> 
				</div>
    		</div>
    		<div class="layui-form-item">
		    	<label for="name" class="layui-form-label">书名:</label>
		    	<div class="layui-input-block">
		      		<input type="text" name="name" id="name" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
	    		</div>
		    </div>
		    <div class="layui-form-item">
		    	<label for="author" class="layui-form-label">作者:</label>
		    	<div class="layui-input-block">
		      		<input type="text" name="author" id="author" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
	    		</div>
		    </div>
		    <div class="layui-form-item">
		    	<label for="brief" class="layui-form-label">内容简介:</label>
		    	<div class="layui-input-block">
		      		<input type="text" name="brief" id="brief" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
	    		</div>
		    </div>
		    <div class="layui-form-item">
		    	<label for="press" class="layui-form-label">出版社:</label>
		    	<div class="layui-input-block">
		      		<input type="text" name="press" id="press" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
	    		</div>
		    </div>
		    <div class="layui-form-item">
		    	<label for="totalQuantity" class="layui-form-label">总数量:</label>
		    	<div class="layui-input-block">
		      		<input type="text" name="totalQuantity" id="totalQuantity" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
	    		</div>
		    </div>
			<div class="layui-form-item" style="float: right; margin-right: 100px;">
			    <button class="layui-btn" lay-submit="" lay-filter="ff">确认</button>
			    <a href="index.htm" type="submit" class="layui-btn">返回</a>
	 		</div>
 		</form>
	</body>
	<script type="text/javascript" src="${BASE_PATH}/static/book/res/lib/layui/layui.js"></script>
	<script>
	layui.use(['form', 'layedit', 'laydate','jquery'], function(){
	  var form = layui.form()
	  ,layer = layui.layer
	  ,$ = layui.jquery;
	  
	 
	  //自定义验证规则
	  form.verify({
	    title: function(value){
	      if(value.length <1){
	        return '标题不能为空';
	      }
	    }
	  });
	  
	  $("#number").on("blur",function(){
	  	var number=$(this).val();
	  	var url="${BASE_PATH}/book/admin/book/find.json?number="+number;
	  	$.ajax({
	  		url:url,
	  		success:function(res){
	  			if(res.result===false){
	  				return ;
	  			}
	  			layer.confirm('数据信息已存在是否需要做出入库操作？', {
			  		btn: ['是', '否']
				}, function(index, layero){
				  	location.href="${BASE_PATH}/book/admin/book/editQuantityPage.htm?id="+res.t.bookId
				}, function(index){
				  //按钮【按钮二】的回调
				});
	  			console.dir(res.t)
	  		}
	  	});
	  })
			  
	  //监听提交
		form.on('submit(ff)', function(data) {
			$.ajax({
				url:"add.json",
				type:"post",
				data:data.field,
				success:function(res){
					if(res.result){
						alert("添加成功")
						location.reload(); 
					}
				}
			})
			return false;
		});
	});

	//上传图片
	layui.use('upload', function(){
	layui.upload({
	    url: '' //上传接口
	    ,success: function(res){ //上传成功后的回调
	      console.log(res)
	    }
	});
	  
	layui.upload({
	    url: '/test/upload.json'
	    ,elem: '#test' //指定原始元素，默认直接查找class="layui-upload-file"
	    ,method: 'get' //上传接口的http类型
	    ,success: function(res){
	      LAY_demo_upload.src = res.url;
	    }
	});
	
});
</script>
</html>
